package com.gxuwz.controller;

import com.gxuwz.model.entity.User;
import com.gxuwz.model.vo.Result;
import com.gxuwz.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/user")
@CrossOrigin
public class UserController {

    @Autowired
    private UserService userService;

    // 读取管理员信息
    @GetMapping("/getUserInfo/{userid}")
    public Result<User> getUserByUserID(@PathVariable String userid) {
        System.out.println("userid"+userid);
        User user = userService.getUserByUserID(userid);
        return user != null ? Result.succeed(user) : Result.error("未找到管理员");
    }

    // 管理员信息修改
    @PutMapping("/userUpdate")
    public Result updateInstructor(@RequestBody User user) {
        System.out.println("user:"+user);
        boolean result = userService.updateUser(user);
        return result ? Result.succeed("个人信息更新成功") : Result.error("个人信息更新失败");
    }
}
